<template>
    <div class="box">
        <nav>
            <h1>电商后台管理登录</h1>
            <el-form
                :model="user"
                :rules="rules"
                ref="elForm"
            >
                <el-form-item prop="username">
                    <el-input
                        prefix-icon="iconfont icon-yonghuming"
                        v-model="user.username"
                        placeholder="请输入用户名"
                    ></el-input>
                </el-form-item>
                <el-form-item prop="password">
                    <el-input
                        prefix-icon="iconfont icon-tianchongxing-"
                        v-model="user.password"
                        show-password
                        placeholder="请输入密码"
                    ></el-input>
                </el-form-item>
                <el-form-item class="login-btn">
                    <el-button
                        type="primary"
                        @click="login"
                    >登录</el-button>
                    <el-button type="info">重置</el-button>
                </el-form-item>
            </el-form>
        </nav>
    </div>
</template>

<script>
import { Login } from "@/http/api";
export default {
  data() {
    return {
      user: {
        username: "admin",
        password: "123456"
      },
      rules: {
        username: [
          { required: true, message: "请输入用户名", trigger: "blur" },
          { min: 5, max: 18, message: "请输入5-18位用户名", trigger: "blur" }
        ],
        password: [
          { required: true, message: "请输入密码", trigger: "blur" },
          { min: 5, max: 10, message: "请输入5-10位密码", trigger: "blur" }
        ]
      }
    };
  },
  mounted() {},
  methods: {
    login() {
      this.$refs.elForm.validate(valid => {
        if (valid) {
          alert("submit!");
          console.log("11", valid);
          Login(this.user).then(res => {
            console.log("res", res);
          });
        } else {
          console.log("error submit!!");
          return false;
        }
      });
    }
  }
};
</script>


<style scoped lang="scss">
.box {
  width: 100%;
  height: 100%;
  background: #2b4b6b;
  position: relative;
}
nav {
  width: 500px;
  height: 300px;
  background: white;
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  padding: 0 20px;
  box-sizing: border-box;
  line-height: 60px;
  border-radius: 5px;
  h1 {
    text-align: center;
  }
}
.login-btn {
  text-align: right;
}
</style>
